package com.mayjean.nacos.config;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.spring.context.annotation.EnableNacos;
import com.mayjean.nacos.data.GlobalDynamicData;
import com.mayjean.nacos.operator.NacosOperator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 */
@Configuration
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "nezha.starters", name = "nacos", havingValue = "true")
@EnableNacos(globalProperties = @NacosProperties())
public class NezhaNacosConfig {

	@NacosInjected
	private ConfigService configService;

	@Bean
	public GlobalDynamicData globalRemoteData() {
		return new GlobalDynamicData();
	}
	
	@Bean
	public NacosOperator nacosOperator() {
		return new NacosOperator(globalRemoteData(), configService);
	}
}

